/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>如果当前店铺处于关闭状态，前台将不能继续浏览该店铺，但是店主仍然可以编辑该店铺</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>店铺列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <div class="fbutton">
        <div class="add" @click="toAdd()">
          <span>
            <i class="el-icon-circle-plus" /> 新增店铺
          </span>
        </div>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-select v-model="store_grade" size="small" clearable placeholder="所属等级">
          <el-option
            v-for="item in storeGrade"
            :key="item.sg_id"
            :label="item.sg_name"
            :value="item.sg_id"
          ></el-option>
        </el-select>
        <el-select v-model="store_class" size="small" clearable placeholder="店铺类别">
          <el-option
            v-for="item in storeClass"
            :key="item.sc_id"
            :label="item.sc_name"
            :value="item.sc_id"
          ></el-option>
        </el-select>
        <el-select v-model="store_state" size="small" clearable placeholder="店铺状态">
          <el-option
            v-for="item in storeState"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-input
          class="searchinput"
          v-model="seller_name"
          size="small"
          placeholder="卖家账号"
          clearable
        />
        <el-input
          class="searchinput"
          v-model="store_name"
          width="10"
          size="small"
          placeholder="店铺名称"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox" v-if="tableData">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="店铺ID" prop="store_id" width="80"></el-table-column>
        <el-table-column label="店铺名称" prop="store_name" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="店主账号" prop="seller.seller_name" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="店主昵称" prop="seller_name" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="推荐人" prop="invite_username" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="店铺会员" prop="store_member_count" width="80"></el-table-column>
        <el-table-column label="所属等级" prop="store_grade.sg_name" width="80"></el-table-column>
        <el-table-column label="店铺类别" prop="store_class.sc_name" width="100"></el-table-column>
        <el-table-column label="进驻日期" prop="store_time_desc" width="100"></el-table-column>
        <el-table-column label="有效期" prop="store_end_time_desc" width="100"></el-table-column>
        <el-table-column label="营业额" prop="store_order_sum" width="100" :formatter="toFixedPrice"></el-table-column>
        <el-table-column label="状态" prop="store_state_desc" width="80"></el-table-column>
        <el-table-column label="推荐" width="80">
          <template slot-scope="scope">
            <div
              :class="scope.row.store_recommend == 1?'yes':'no'"
              @click="updateRecommend(scope.row)"
            >
              <i :class="scope.row.store_recommend == 1?'fa fa-check-circle':'fa fa-ban'"></i>
              <span v-text="scope.row.store_recommend == 1?'是':'否'"></span>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button size="small" @click="detail(scope.row)" icon="el-icon-zoom-in">查看</el-button>
              <el-button
                size="small"
                @click="toEdit(scope.row.store_id)"
                icon="el-icon-edit-outline"
              >编辑</el-button>
              <el-button
                size="small"
                @click="toStoreClass(scope.row.store_id, scope.row.store_name)"
                icon="el-icon-s-tools"
              >经营类目</el-button>
              <el-button size="small" @click="remove(scope.row.store_id)" icon="el-icon-delete">删除</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import {
  getStorePage,
  updateStore,
  deleteStore,
  getStoreGradeList,
  getStoreClass
} from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      store_grade: null,
      store_class: null,
      store_state: null,
      seller_name: null,
      store_name: null,
      storeGrade: [],
      storeClass: [],
      storeState: [
        {
          value: 0,
          label: "关闭"
        },
        {
          value: 1,
          label: "开启"
        },
        {
          value: 2,
          label: "审核中"
        },
        {
          value: 3,
          label: "即将到期"
        },
        {
          value: 4,
          label: "已到期"
        },
        {
          value: 5,
          label: "已删除"
        }
      ]
    };
  },
  components: {},
  created() {
    this.getPage();
    this.getStoreGradeList();
    this.getStoreClass();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      getStorePage({
        is_own_shop: 0,
        grade_id: this.store_grade,
        sc_id: this.store_class,
        store_state: this.store_state,
        seller_name: this.seller_name,
        store_name: this.store_name,
        p: this.currentPage,
        size: this.pageSize
      }).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    },
    updateRecommend(row) {
      var store = {
        store_id: row.store_id,
        store_recommend: row.store_recommend == 1 ? 0 : 1
      };
      var that = this;
      updateStore(store).then(function(res) {
        if (res.status == 1) {
          that.getPage();
        }
      });
    },
    detail(row) {
      this.$router.push({
        name: "store_detail",
        params: {
          userId: row.user_id,
          sgId: row.grade_id,
          storeId: row.store_id,
          currentPage: this.currentPage
        }
      });
    },
    remove(id) {
      var that = this;
      this.$confirm("是否删除该店铺?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          deleteStore(id).then(function(res) {
            if (res.status == 1) {
              that.getPage();
              that.$message({
                type: "success",
                message: "删除成功!"
              });
            } else {
              that.$message.error({
                message: res.msg
              });
            }
          });
        })
        .catch(() => {
          that.$message.info({
            message: "已取消删除"
          });
        });
    },
    getStoreGradeList() {
      var that = this;
      getStoreGradeList().then(function(res) {
        that.storeGrade = res;
      });
    },
    getStoreClass() {
      var that = this;
      getStoreClass().then(function(res) {
        that.storeClass = res;
      });
    },
    toAdd() {
      this.$router.push({
        name: "store_add",
        params: {
          isOwnShop: 0,
          currentPage: this.currentPage
        }
      });
    },
    toEdit(storeId) {
      this.$router.push({
        name: "store_edit",
        params: {
          isOwnShop: 0,
          storeId: storeId,
          currentPage: this.currentPage
        }
      });
    },
    toStoreClass(storeId, storeName) {
      this.$router.push({
        name: "store_class_info",
        params: {
          storeId: storeId,
          storeName: storeName,
          currentPage: this.currentPage
        }
      });
    },
    toFixedPrice(row) {
      return row.store_order_sum.toFixed(2);
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
